package com.kupurui.asteacher.ui.index;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.ListView;
import android.widget.TextView;

import com.android.frame.util.AppJsonUtil;
import com.kupurui.asteacher.R;
import com.kupurui.asteacher.adapter.HomeworkCompletionAdapter;
import com.kupurui.asteacher.bean.HomeworkCompletionBean;
import com.kupurui.asteacher.http.Teacher;
import com.kupurui.asteacher.ui.BaseAty;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 作业完成情况
 * Created by Administrator on 2017/7/18.
 */

public class HomeworkCompletionkAty extends BaseAty {

    @Bind(R.id.tv_bar_title)
    TextView tvBarTitle;
    @Bind(R.id.m_toolbar)
    Toolbar mToolbar;
    @Bind(R.id.listview)
    ListView listview;
    @Bind(R.id.tv_empty)
    TextView tvEmpty;

    List<HomeworkCompletionBean> list;
    HomeworkCompletionAdapter adapter;

    private String sid = "";

    @Override
    public int getLayoutId() {
        return R.layout.homework_completion_aty;
    }

    @Override
    public void initData() {
        if (getIntent().getExtras()!=null){
            sid = getIntent().getStringExtra("sid");
        }
        initToolbar(mToolbar,"作业完成情况");
        list = new ArrayList<>();
        adapter = new HomeworkCompletionAdapter(this,list,R.layout.homework_completion_item);
        listview.setAdapter(adapter);
        listview.setEmptyView(tvEmpty);
    }

    @Override
    public void requestData() {
        showLoadingContent();
        new Teacher().work_degree(sid,this,0);
    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        switch (what){
            case 0:
                list.clear();
                list.addAll(AppJsonUtil.getArrayList(result,HomeworkCompletionBean.class));
                adapter.notifyDataSetChanged();
                break;
        }
        super.onSuccess(result, call, response, what);
    }
}
